<?php

namespace app\supplier\controller\setting;

use app\common\model\settings\Setting as SettingModel;
use app\supplier\controller\Controller;
use app\supplier\model\plus\agent\Setting as AgentSettingModel;
use app\supplier\model\product\Product as ProductModel;

/**
 * 分销设置控制器
 */
class Agent extends Controller
{

    public $pay_type = [
        ['id' => '10', 'name' => '微信支付'],
        ['id' => '20', 'name' => '支付宝'],
        ['id' => '30', 'name' => '银行卡']
    ];

    public $pay_type1 = [
        10 => '微信支付',
        20 => '支付宝',
        30 => '银行卡'
    ];

    /**
     * 分销设置
     */
    public function index()
    {
        $pay_type = $this->pay_type;
        $data = AgentSettingModel::getAll($this->getSupplierId());
        return $this->renderSuccess('', compact('data', 'pay_type'));
    }

    /**
     * 基础信息设置
     */
    public function basic()
    {
        $param = $this->postData();
        $data['basic'] = $param;
        return $this->edit($data);
    }

    /**
     * 修改
     */
    public function edit($data)
    {
        $model = new AgentSettingModel;
        if ($model->edit($data,$this->getSupplierId())) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }

}